home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / dos / runcommand.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-13  |  2.7 KB  |  120 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: runcommand.c,v 1.6 1996/09/13 17:50:09 digulla Exp $
  4.     $Log: runcommand.c,v $
  5.     Revision 1.6  1996/09/13 17:50:09  digulla
  6.     Use IPTR
  7.  
  8.     Revision 1.5  1996/09/11 16:54:23  digulla
  9.     Always use __AROS_SLIB_ENTRY() to access shared external symbols, because
  10.     some systems name an external symbol "x" as "_x" and others as "x".
  11.     (The problem arises with assembler symbols which might differ)
  12.  
  13.     Revision 1.4  1996/08/13 13:52:51  digulla
  14.     Replaced <dos/dosextens.h> by "dos_intern.h" or added "dos_intern.h"
  15.     Replaced __AROS_LA by __AROS_LHA
  16.  
  17.     Revision 1.3  1996/08/01 17:40:57  digulla
  18.     Added standard header for all files
  19.  
  20.     Desc:
  21.     Lang: english
  22. */
  23. #include <exec/memory.h>
  24. #include <clib/exec_protos.h>
  25. #include <utility/tagitem.h>
  26. #include <dos/filesystem.h>
  27. #include <clib/dos_protos.h>
  28. #include "dos_intern.h"
  29.  
  30. LONG __AROS_SLIB_ENTRY(RunProcess,Dos)(struct Process *proc,
  31.     struct StackSwapStruct *sss, STRPTR argptr, ULONG argsize,
  32.     LONG_FUNC entry, struct DosLibrary *DOSBase);
  33.  
  34. /*****************************************************************************
  35.  
  36.     NAME */
  37.     #include <clib/dos_protos.h>
  38.  
  39.     __AROS_LH4(LONG, RunCommand,
  40.  
  41. /*  SYNOPSIS */
  42.     __AROS_LHA(BPTR,   segList,   D1),
  43.     __AROS_LHA(ULONG,  stacksize, D2),
  44.     __AROS_LHA(STRPTR, argptr,    D3),
  45.     __AROS_LHA(ULONG,  argsize,   D4),
  46.  
  47. /*  LOCATION */
  48.     struct DosLibrary *, DOSBase, 84, Dos)
  49.  
  50. /*  FUNCTION
  51.  
  52.     INPUTS
  53.  
  54.     RESULT
  55.  
  56.     NOTES
  57.  
  58.     EXAMPLE
  59.  
  60.     BUGS
  61.  
  62.     SEE ALSO
  63.  
  64.     INTERNALS
  65.  
  66.     HISTORY
  67.     29-10-95    digulla automatically created from
  68.                 dos_lib.fd and clib/dos_protos.h
  69.  
  70. *****************************************************************************/
  71. {
  72.     __AROS_FUNC_INIT
  73.     __AROS_BASE_EXT_DECL(struct DosLibrary *,DOSBase)
  74.  
  75.     STRPTR oldargs;
  76.     LONG oldresult;
  77.  
  78.     /* Get pointer to process structure */
  79.     struct Process *me=(struct Process *)FindTask(NULL);
  80.  
  81.     UBYTE *stack;
  82.     LONG ret;
  83.     struct StackSwapStruct sss;
  84.  
  85.     stack=(UBYTE *)AllocMem(stacksize,MEMF_ANY);
  86.     if(stack==NULL)
  87.     return -1;
  88.  
  89.     sss.stk_Lower=stack;
  90.     sss.stk_Upper=(IPTR)stack+stacksize;
  91.  
  92.     oldresult=me->pr_Result2;
  93.     if(me->pr_CIS)
  94.     Flush(me->pr_CIS);
  95.     if(me->pr_COS)
  96.     Flush(me->pr_COS);
  97.     if(me->pr_CES)
  98.     Flush(me->pr_CES);
  99.     me->pr_Result2=oldresult;
  100.  
  101.     oldargs=me->pr_Arguments;
  102.     me->pr_Arguments=argptr;
  103.     ret=__AROS_SLIB_ENTRY(RunProcess,Dos)(me,&sss,argptr,argsize,
  104.         (APTR)BADDR(segList+1),DOSBase);
  105.     me->pr_Arguments=oldargs;
  106.  
  107.     oldresult=me->pr_Result2;
  108.     if(me->pr_CIS)
  109.     Flush(me->pr_CIS);
  110.     if(me->pr_COS)
  111.     Flush(me->pr_COS);
  112.     if(me->pr_CES)
  113.     Flush(me->pr_CES);
  114.     me->pr_Result2=oldresult;
  115.  
  116.     FreeMem(stack,stacksize);
  117.     return ret;
  118.     __AROS_FUNC_EXIT
  119. } /* RunCommand */
  120.